package mya.mes.mdc.logic.mqtt;

import com.fasterxml.jackson.databind.ObjectWriter;
import mya.common.model.json.JsonHelper;
import mya.mes.mdc.local.alarm.MdcAlarmResult;
import mya.mes.mdc.share.vo.plc.PlcTagVo;
import mya.mes.mdc.websocket.MdcBroadcast;
import mya.mes.mdc.websocket.MdcBroadcast1;

import java.util.List;

public class WebsocketBroadCast {

    private ObjectWriter plcTagResultWriter;

    public WebsocketBroadCast() {

        plcTagResultWriter = JsonHelper.objectMapper.writerFor(PlcTagResult.class);

    }

    public void broadcast(Long mqttMsgId, List<PlcTagVo> voList, MdcAlarmResult alarmResult) throws Exception {

        PlcTagResult plcTagResult = new PlcTagResult();
        plcTagResult.objectId = mqttMsgId;
        plcTagResult.data = voList;
        plcTagResult.alarmResult = alarmResult;
        String jsonStr =
                plcTagResultWriter.writeValueAsString(plcTagResult);
        MdcBroadcast.broadcast(jsonStr);
    }
}
